package de.karnik.dokobu.persistence;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class DoKoBuUser {

	public static final int ROLE_USER = 0;
	public static final int ROLE_EDITOR = 1;
	public static final int ROLE_ADMIN = 2;
	
    @PrimaryKey
    @Persistent
	private String googleID = null;
    @Persistent
	private String displayName = null;
    @Persistent
	private int role = ROLE_USER;

	private DoKoBuUser() {}
	
	public DoKoBuUser( String googleID, String displayName, int role ) {
		this();
		this.setGoogleID( googleID );
		this.setDisplayName( displayName );
		this.setRole( role );
	}

	public int getRole() {
		return this.role;
	}
	
	public void setRole( int role ) {
		
		switch( role ) {
			case ROLE_USER:
			case ROLE_EDITOR:
			case ROLE_ADMIN:
				this.role = role;
				break;
			default:
				this.role = ROLE_USER;
		}
	}
	
	public String getGoogleID() {
		return this.googleID;
	}

	public void setGoogleID( String googleID ) {
		this.googleID = googleID;
	}

	public void setDisplayName( String displayName ) {
		this.displayName = displayName;
	}

	public String getDisplayName() {
		return this.displayName;
	}
}